package com.leyou.item.web;

import com.leyou.common.vo.PageResult;
import com.leyou.item.dto.BrandDTO;
import com.leyou.item.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 分页条件查询
     */
    @GetMapping("/page")
    public ResponseEntity<PageResult<BrandDTO>> brandPageQuery(
            @RequestParam(value="key",required = false) String key,
            @RequestParam(value="page", defaultValue = "1") Integer page,
            @RequestParam(value="rows", defaultValue = "5") Integer rows,
            @RequestParam(value="sortBy",defaultValue = "id") String sortBy,
            @RequestParam(value="desc", defaultValue = "false") Boolean desc
    ){
        //调用业务层方法
        PageResult<BrandDTO> result = brandService.brandPageQuery(key, page, rows, sortBy, desc);
        //返回页面
        return ResponseEntity.ok(result);
    }
}